﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Docentric.Examples.Browser
{
    public abstract class ExampleBase
    {
        // Properties
		public string Name { get; protected set; }
        public string Title { get; protected set; }
        public string Description { get; protected set; }
		public string HelpTopicPage { get; protected set; }
        public string DirectoryPath { get; private set; }


        // Constructor
        public ExampleBase()
        {
            // Set the directory path of the executing assembly
            string directoryPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
        }
        

        /// <summary>
        /// Generates the report for this example.
        /// </summary>
        /// <returns>File full name of the genarated report document.</returns>
        public abstract string GenerateReport();


        /// <summary>
        /// Opens the report template file for this example.
        /// </summary>
        /// <returns>Returns the file stream of the report template file.</returns>
        protected Stream GetReportTemplate()
        {
			if (!File.Exists(TemplateFileName))
            {
				throw new Exception(string.Format("Report template '{0}' is not found", TemplateFileName));
            }
			return File.OpenRead(TemplateFileName);
        }


		// ApplicationPath
		protected string ApplicationPath
		{
			get
			{
				return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
			}
		}


		// TemplateFileName
		public string TemplateFileName
		{
			get
			{
				return System.IO.Path.Combine(ApplicationPath, "ExampleResources\\" + Name + "\\Template.docx");
			}
		}


		// TemplateImageSource
		public ImageSource TemplateImageSource
		{
			get
			{
				return new BitmapImage(new Uri("/ExampleResources/" + Name + "/TemplateImage.jpg", UriKind.Relative));
			}
		}


		// ReportImageSource
		public ImageSource ReportImageSource
		{
			get
			{
				return new BitmapImage(new Uri("/ExampleResources/" + Name + "/ReportImage.jpg", UriKind.Relative));
			}
		}
    }
}
